# run_tests.py
from utils.email_utils import EmailUtils
import pytest
import os
from utils.log_utils import log


def run_tests():
    try:
        log.info("开始执行测试...")
        # 执行测试
        pytest.main(["-s", "-v", "--alluredir=reports/allure_results"])

        # 生成报告
        os.system("allure generate reports/allure_results -o reports/allure_reports --clean")
        log.info("测试执行完成，生成报告成功")
        # 发送报告
        email = EmailUtils()
        email.send_email()
    except Exception as e:
        log.error(f"测试执行失败: {str(e)}")
        raise


if __name__ == '__main__':
    run_tests()
